<%@ include file="/WEB-INF/views/commonJSTL.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>${s_UserPharmacy.pharmacy.name}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%@ include file="/WEB-INF/views/commonResources.jsp" %>
<script src="<c:url value="/resources/js/jquery.jstree.js" />"></script>

<script type="text/javascript">
	$(document).ready(function(){	
		$("#formGrupo").validate({
	        submitHandler: function(form) {
	       		form.submit();
	        }
	    }); 
		
		$("input[name='_typePharmacy']").change(function(){
            var tipoFecha = parseInt($("input[name='_typePharmacy']:checked").val(),10);
            if(tipoFecha == 2){
                $("#typePharmacyDiv").css("display", "block");
            }else{
                $("#typePharmacyDiv").css("display", "none");
            }
        });
		
		//permit only numbers
		$('.numberOnlyNumber').keyup(function () {
	         if (this.value != this.value.replace(/[^0-9]/g,'')) {
	            this.value = this.value.replace(/[^0-9]/g, '');
	         }
	     });
		
		//permit only text
		$('.lettersOnly').keyup(function () {
	         if (this.value != this.value.replace(/[^A-Za-z\s]/g, '')) {
	            this.value = this.value.replace(/[^A-Za-z\s]/g, '');
	         }
	     });
	});

	function mainPharmacies(countryId,regionId){
		location.href = "pharmacies?_menuId=1&_subMenuId=2&_optionId=1&_countryId="+countryId+"&_regionId="+regionId;
	}
	
	/*Validando el email*/
	function validateEmail(emailField){
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        if (reg.test(emailField.value) == false) 
        {
            alert('Dirección de correo electrónico no válida');
            return false;
        }

        return true;
	}
</script>
</head>

<body>
<div id="top-wrap">
	<%@include file="../../../head.jsp"  %>
	<div id="bodySpace">
		
	    <div class="clearfix" id="middle" style="position: absolute">  <!-- aqui va la ruta -->
	        <!-- aqui va el arbol de entrada -->
	        <div id="breadcrumb">
	            <ul>
                	<li><a href="<spring:url value="/mainFront?" htmlEscape="true" />">Home</a></li>	
                    <li><span style="color:#666"><fmt:message key="title.configuration"/></span></li>
                    <li><span style="color:#666"><fmt:message key="title.customers"/></span></li>
                    <li class="current-page"><span class="end"><span class="middle"><fmt:message key="title.pharmacies"/></span></span></li>
                </ul>
	        </div>
	    </div>
	    
	    <div id="principal">
            <!-- izquierda -->
            <div class="cuerpo2y" style="border: 0px solid"><br/><br/><!-- estos break son necesarios ya q uso absolute en css  cuerpo izquierdo-->
                <div class="izq">
					<%@include file="../../../bodyIzq.jsp" %>	
                </div>
                
                <div class="medio" style="border: 0px solid">
					
					<h2 class="decorado">
					<c:choose>		
						<c:when test="${pharmacy.pharmacyId == null}">
							<fmt:message key="show.register"/> <fmt:message key="title.pharmacy"/>
						</c:when>
						<c:otherwise>
							<fmt:message key="show.modify"/> <fmt:message key="title.pharmacy"/>
						</c:otherwise>
					</c:choose>					
					</h2>&nbsp;
					
					<h3 class="decorado">${region.countryId.name} - ${region.name}</h3>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					
					<form:form method="post" id="formGrupo" commandName="pharmacy">   
						<form:hidden path="pharmacyId"/>                        
						<div style="clear: both">
						    <label class="form_align43"><fmt:message key="form.type.pharmacy"/> :</label>
						    <c:choose>		
								<c:when test="${pharmacy.pharmacyId != null}">
									<c:choose>
										<c:when test="${tempPhapharmacyId != null}">
											<input type="radio" name="_typePharmacy" id="central" value="1" /><label for="central">&nbsp;<fmt:message key="form.central"/>&nbsp;&nbsp;</label>&nbsp;&nbsp;
						    				<input type="radio" name="_typePharmacy" id="branchOffice" checked="checked"  value="2"/><label for="branchOffice">&nbsp;<fmt:message key="form.branchOffice"/>&nbsp;&nbsp;</label>
						    				<c:set var="pharmacySelectedBranchOffice" scope="page"><fmt:message key="show.form.selected.branchOffice.pharmacy"/>.</c:set>
											<div id="typePharmacyDiv" style="clear: both">
											    <label class="form_align43"><fmt:message key="form.branchOffice.pharmacy"/> :</label>
											    <select name="_tempPharmacyId" id="_tempPharmacyId" class="required form_input_align" title="${pharmacySelectedBranchOffice}">
													<option value=""><fmt:message key="form.selected"/></option>
													<c:forEach var="item" items="${listPhapharmacy}">
														<c:set var="selec" value="" />
		                                        		<c:if test="${tempPhapharmacyId == item.pharmacyId}">
		                                        			<c:set var="selec" value="selected='selected'" />
		                                        		</c:if>
														<option value="${item.pharmacyId}" ${selec}>${item.name}</option>
													</c:forEach>            							
												</select>	
											    <label class="error">*</label>
											</div>
										</c:when>
										<c:otherwise>
											<input type="radio" name="_typePharmacy" id="central" value="1" class="form_input_align_NoFloat" checked="checked" /><label for="central">&nbsp;<fmt:message key="form.central"/>&nbsp;&nbsp;</label>&nbsp;&nbsp;
						    				<input type="radio" name="_typePharmacy" id="branchOffice" value="2"/><label for="branchOffice">&nbsp;<fmt:message key="form.branchOffice"/>&nbsp;&nbsp;</label>
										</c:otherwise>
									</c:choose>
								</c:when>
								<c:otherwise>
									<input type="radio" name="_typePharmacy" id="central" value="1" class="form_input_align_NoFloat" checked="checked" /><label for="central">&nbsp;<fmt:message key="form.central"/>&nbsp;&nbsp;</label>&nbsp;&nbsp;
						    		<input type="radio" name="_typePharmacy" id="branchOffice" value="2"/><label for="branchOffice">&nbsp;<fmt:message key="form.branchOffice"/>&nbsp;&nbsp;</label>
								</c:otherwise>
							</c:choose> 
						</div>    
												
						<c:set var="pharmacySelectedBranchOffice" scope="page"><fmt:message key="show.form.selected.branchOffice.pharmacy"/>.</c:set>
						<div id="typePharmacyDiv" style="clear: both; display: none">
						    <label class="form_align43"><fmt:message key="form.branchOffice.pharmacy"/> :</label>
						    <select name="_tempPharmacyId" id="_tempPharmacyId" class="required form_input_align" title="${pharmacySelectedBranchOffice}">
								<option value=""><fmt:message key="form.selected"/></option>
								<c:forEach var="item" items="${listPhapharmacy}">
									<option value="${item.pharmacyId}">${item.name}</option>
								</c:forEach>            							
							</select>	
						    <label class="error">*</label>
						</div>						
						</br></br> 
						
						<c:set var="localityShow" scope="page"><fmt:message key="show.form.selected.locality"/>.</c:set>																																				                             												
						<div style="clear:both;">
							<label class="form_align43"><fmt:message key="form.locality"/> :</label>
						    <select name="_tempLocalityId" id="_tempLocalityId" class="required form_input_align" title="${localityShow}">
								<option value=""><fmt:message key="form.selected"/></option>
								<c:forEach var="item" items="${listLocality}">
									<c:set var="selec" value="" />
                               		<c:if test="${pharmacy.locality.localityPK.localityId == item.localityPK.localityId}">
                               			<c:set var="selec" value="selected='selected'" />
                               		</c:if>
									<option value="${item.localityPK.localityId}" ${selec}>${item.name}</option>
								</c:forEach>            							
							</select>	
						    <label class="error">*</label>
						</div>
						
						<c:set var="name" scope="page"><fmt:message key="show.form.name"/>.</c:set>																																				                             												
						<div style="clear:both;">
							<label class="form_align43"><fmt:message key="form.name"/>:</label>
							<form:input path="name" id="name" class="required form_input_align letterSpace lettersOnly" maxlength="25" title="${name}" autofocus="autofocus" placeholder="letras"/>
							<label class="error"><form:errors path="name" cssClass="error"></form:errors>*</label>
						</div>
						
						<c:set var="socialReason" scope="page"><fmt:message key="show.form.socialReason"/>.</c:set>																																				                             												
						<div style="clear:both;">
							<label class="form_align43"><fmt:message key="form.socialReason"/>:</label>
							<form:input path="socialReason" id="socialReason" class="required form_input_align letterSpace lettersOnly" title="${socialReason}" placeholder="letras"/>
							<label class="error">*</label>
						</div>
						
						<c:set var="nit" scope="page"><fmt:message key="show.form.nit"/>.</c:set>																																				                             												
						<div style="clear:both;">
							<label class="form_align43"><fmt:message key="form.nit"/>:</label>
							<form:input path="nit" id="nit" class="required form_input_align letterSpace numberOnlyNumber" maxlength="25" title="${nit}" placeholder="números"/>
							<label class="error">*</label>
						</div>
						
						<c:set var="address" scope="page"><fmt:message key="show.form.address"/>.</c:set>																																				                             												
						<div style="clear:both;">
							<label class="form_align43"><fmt:message key="form.address"/>:</label>
							<form:input path="address" id="address" class="required form_input_align letterSpace" title="${address}" placeholder="texto"/>
							<label class="error">*</label>
						</div>
						
						<c:set var="email" scope="page"><fmt:message key="show.form.email"/>.</c:set>																																				                             												
						<div style="clear:both;">
							<label class="form_align43"><fmt:message key="form.email"/>:</label>
							<form:input path="email" id="email" class="required form_input_align letterSpace" title="${email}" placeholder="name@example.com" onblur="validateEmail(this);"/>
							<label class="error">*</label>
						</div>
						
						<div style="clear: both">
							<label class="form_align43">&nbsp;</label>
							<table border="0" style="float: left">
								<fmt:message key="button.register" var="varSubmit" />
								<c:if test="${pharmacy.pharmacyId != null}">
									<fmt:message key="button.modify" var="varSubmit" />
								</c:if>								
								<tr>
									<td style="text-align:right"><br/><input type="submit" value="${varSubmit}" name="action"  class="boton" title="<fmt:message key="onclick.for"/> ${varSubmit}" />&nbsp;&nbsp;</td>
									<td><br/>&nbsp;&nbsp;<input type="button" value="<fmt:message key="button.cancel"/>" name="action" onclick="mainPharmacies('${param._countryId}','${param._regionId}')" class="boton" title="<fmt:message key="onclick.cancel"/>"/></td>
								</tr>
							</table>
						</div>
					</form:form>
                </div>
            </div>
            <div class="yDer" style="border: 1px solid #ccc;">
                  <%@include file="../../../notices.jsp" %>                       
            </div><!--end of rightPan-->
        </div><!--end main content -->
	</div>
</div>
</body>
</html>
